package com.dy.service;

import com.dy.entity.Cinema;
import com.dy.entity.Sale;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Auther: dy
 * @Date: 2022/4/16 - 04 - 16 - 13:13
 * @Description: com.dy.service
 * @version: 1.0
 */
@Service
public class FeignCinema {
    @Autowired
    private IFeignCinemaService feignCinemaService;
    @Autowired
    private ISaleService saleService;

    @Scheduled(cron = "0 1 22 * * ?")//每天8点刷新
    public void refreshCinema(){
       List<Cinema> cinemas = feignCinemaService.refreshCinema();
        cinemas.stream().forEach(r->{
            Sale sale = new Sale();
            sale.setSaleNum(0l);
            sale.setCinameNum(r.getCinemaNum());
            sale.setSaleTime(r.getCinemaTime());
            sale.setCinameSerial(r.getCinemaSerial());
            sale.setSaleState(0l);
            sale.setCinameName(r.getCinemaName());
            sale.setSalePrice(r.getCinemaPrice());
            saleService.save(sale);
        });
    }
}
